﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.IO;

namespace Fulcrum.DispatcherProxies
{
    public class DispatcherProxySettings : ISettings
    {
        public DispatcherProxySettings()
        {
            // nothing
        }

        public void ValidateSettings()
        {
            if (String.IsNullOrEmpty(this.TargetAssembly))
            {
                ThrowBadSettingException("A target assembly is required.");
            }

            if (String.IsNullOrEmpty(this.Copyright))
            {
                ThrowBadSettingException("A copyright message is required.");
            }

            if (String.IsNullOrEmpty(this.Company))
            {
                ThrowBadSettingException("A company name is required.");
            }

            if (String.IsNullOrEmpty(this.Namespace))
            {
                ThrowBadSettingException("A namespace is required.");
            }

            if (false == File.Exists(this.TargetAssembly))
            {
                ThrowBadSettingException("The target assembly '{0}' doesn't exist.", this.TargetAssembly);
            }

        }

        private void ThrowBadSettingException(string format, params object[] args)
        {
            var message = String.Format(format,args);
            var exception = new ApplicationException(message);
            throw exception;
        }

        [Setting(Description = "The assembly which contains types to be proxied.")]
        public string TargetAssembly
        {
            get;
            set;
        }

        [Setting(Description = "The copyright for the generated files.")]
        public string Copyright
        {
            get;
            set;
        }

        [Setting(Description = "The company for the generated files.")]
        public string Company
        {
            get;
            set;
        }

        [Setting(Description = "The namespace for the generated code.")]
        public string Namespace
        {
            get;
            set;
        }
    }
}
